package com.ym.medical.domain.bo.msg;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.ym.medical.enums.WxMsgTypeEnum;
import lombok.Data;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: DaiKuangYin
 * @Date: 2020/1/7 10:51
 */

@Data
@JsonInclude(JsonInclude.Include.NON_NULL)
public class MpTemplateParam implements Serializable {
    private String value;
    private String color = "#173177";

    public MpTemplateParam(String value) {
        this.value = value;
    }

    public MpTemplateParam(String value, String color) {
        this.value = value;
        this.color = color;
    }

    public static List<MpTemplateParam> generateMpTemplateParam(String[] params) {
        List<MpTemplateParam> paras=new ArrayList<MpTemplateParam>();
        for (int i = 0; i < params.length; i++) {
            paras.add(new MpTemplateParam(params[i]));
        }
        return paras;
    }


    public static List<MpTemplateParam> generateReplyMpTemplateParam(String[] params) {
        SimpleDateFormat sdf = new SimpleDateFormat();// 格式化时间
        sdf.applyPattern("yyyy-MM-dd HH:mm:ss");// a为am/pm的标记
        Date date = new Date();// 获取当前时间

        List<MpTemplateParam> paras=new ArrayList<MpTemplateParam>();
        paras.add(new MpTemplateParam("患者问题处理情况"));
        paras.add(new MpTemplateParam(sdf.format(date)));
        paras.add(new MpTemplateParam(params[2]));
        paras.add(new MpTemplateParam(params[0]));
        paras.add(new MpTemplateParam(params[1]));
        paras.add(new MpTemplateParam(params[3]));
        return paras;
    }

    public static List<MpTemplateParam> generateRefundMpTemplateParam(String[] params) {
        List<MpTemplateParam> paras=new ArrayList<MpTemplateParam>();
        paras.add(new MpTemplateParam("您好，您已成功退费"));
        paras.add(new MpTemplateParam(params[0]));
        paras.add(new MpTemplateParam(params[3]));
        paras.add(new MpTemplateParam(params[2]));
        paras.add(new MpTemplateParam("请您注意查收。亚米医疗祝您身体健康。"));
        return paras;
    }

    public static List<MpTemplateParam> generatePayMpTemplateParam(String[] params) {
        List<MpTemplateParam> paras=new ArrayList<MpTemplateParam>();
        paras.add(new MpTemplateParam("您的订单已支付成功"));
        paras.add(new MpTemplateParam(params[0]));
        paras.add(new MpTemplateParam(params[1]));
        paras.add(new MpTemplateParam(params[2]));
        paras.add(new MpTemplateParam("感谢您的使用"));
        return paras;
    }

    /**
     * 构建消息模板
     * @param wxMsgTypeEnum
     * @param params
     * @return
     */
    public static List<MpTemplateParam> generateTemplateParam(WxMsgTypeEnum wxMsgTypeEnum, String[] params) {
        List<MpTemplateParam> mpParam = new ArrayList<>();
        switch (wxMsgTypeEnum) {
            case MP_DOCTOR_REPLY_MSG:
                mpParam = generateReplyMpTemplateParam(params);
                break;
            case MP_PAY_MSG:
                mpParam = generatePayMpTemplateParam(params);
                break;
            case MP_REFUND_MSG:
                mpParam = generateRefundMpTemplateParam(params);
                break;
            default:
                mpParam = generateMpTemplateParam(params);
                break;
        }
        return mpParam;
    }


    @Override
    public String toString() {
        return "MpTemplateParam{" +
                "value='" + value + '\'' +
                ", color='" + color + '\'' +
                '}';
    }
}